
const fs = jest.genMockFromModule('fs')
const _fs = jest.requireActual('fs')
Object.assign(fs, _fs)

const readFileMocks = {}

fs.setReadMock = (path, error, data) => {
    readFileMocks[path] = [error, data]
}

fs.readFile = (path, options, callback) => {
    console.log('我其实执行的是这个呀')
    if (callback === undefined) {
        callback = options
    }
    if (path in readFileMocks) {
        callback(...readFileMocks[path])
    } else {
        _fs.readFile(path, options, callback)
    }
}
let writeMocks = {}

fs.setWriteFileMock = (path, fn) => {
    writeMocks[path] = fn
}

fs.writeFile = (path, data, options, callback) => {
    if (path in writeMocks) {
        writeMocks[path](path, data, options, callback)
    } else {
        _fs.writeFile(path, data, options, callback)
    }
}
module.exports = fs